/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;


import bean.Aula;
import bean.Horarios;
import bean.Professor;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Júnior
 */
public class PainelProfessorDao {
    
    public List<Professor> listarProfessor() {

        EntityManager em = FabricaConexao.getConexao().createEntityManager();
        List<Professor> lista;
        Query query = em.createQuery("select p from Professor p");
        lista = query.getResultList();
        em.close();
        return lista;
    }
    
    public List<Horarios> listarHorarios(String turno) {

        EntityManager em = FabricaConexao.getConexao().createEntityManager();
        List<Horarios> lista;
        Query query = em.createQuery("select h from Horarios as h where h.turno = '"+turno+"' order by h.inicio asc");
        lista = query.getResultList();
        em.close();
        return lista;
    }
    
    public List<Aula> listarAulas(int professor, String turno) {

        EntityManager em = FabricaConexao.getConexao().createEntityManager();
        List<Aula> lista;
        Query query = em.createQuery("select a from Aula a inner join a.disciplina.professores d left join a.horario h where d.matricula = "+professor+" and h.turno = '"+turno+"'" );
       /* query.setParameter("tperiodo", periodo); 
        query.setParameter("tturno", turno);*/
        lista = query.getResultList();
        em.close();
        return lista;
    }
    
}
